package cn.singno.bob.common.utils;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.google.common.collect.Maps;

/**
 * <p>名称：EntityUtils.java</p>
 * <p>描述： BeanUtils工具。转换异常抛出</p>
 * <pre>
 *    
 * </pre>
 * @author 鲍建明
 * @date 2014年8月6日 上午11:00:03
 * @version 1.0.0
 */
public class EntityUtils {

	private static Log logger = LogFactory.getLog(EntityUtils.class);
	
	/**
	 *　BeanUtils.copyProperties(dest, orig);
	 * @param dest
	 * @param orig
	 */
	public static void copyBean(Object dest, Object orig) {
		
		try {
			BeanUtils.copyProperties(dest, orig);
		} catch (IllegalAccessException e) {
			logger.error("调用　BeanUtils.copyProperties(dest, orig) 参数错误", e);
		} catch (InvocationTargetException e) {
			logger.error("调用　BeanUtils.copyProperties(dest, orig) 调用目标异常", e);
		}
	}
	
	/**
	 * obj --> map<String, Object>
	 * @param obj
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static Map<String, Object> describe(Object obj){
		if(obj == null){
			return Maps.newHashMap();
		}
		try {
			return BeanUtils.describe(obj);
		} catch (IllegalAccessException | InvocationTargetException
				| NoSuchMethodException e) {
			logger.error(e);
			return Maps.newHashMap();
		}
		
		
	}
	
	
}
 